package com.api.shopapi.controller;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.api.shopapi.config.MessageConfig;
import com.api.shopapi.entity.*;
import com.api.shopapi.entity.dto.ElderlyDTO;
import com.api.shopapi.entity.dto.UserDTO;
import com.api.shopapi.entity.dto.VolunteerTeamDTO;
import com.api.shopapi.service.*;
import com.api.shopapi.util.SendMessageUtil;
import com.api.shopapi.util.smsTencent.SendSms;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.*;

//用户

@RestController
@RequestMapping("User")
public class UserController  extends BaseController {

    //@Autowired
    //private HttpServletRequest request;

    @Autowired
    @Qualifier("UserServiceImplOne")
    private UserService userService;

    @Autowired
    @Qualifier("UserAppInfoServiceImplOne")
    private UserAppInfoService userAppInfoService;

    @Autowired
    @Qualifier("VerificationCodeServiceImplOne")
    private VerificationCodeService verificationCodeService;

    @Autowired
    @Qualifier("ElderlyServiceImplOne")
    private ElderlyService elderlyService;

    @Autowired
    @Qualifier("StaffServiceImplOne")
    private StaffService staffService;


    @Autowired
    @Qualifier("GovernmentServiceImplOne")
    private GovernmentService governmentService;

    @Autowired
    @Qualifier("ElderlyClassServiceImplOne")
    private ElderlyClassService elderlyClassService;


    @Autowired
    @Qualifier("ZoneServiceImplOne")
    private ZoneService zoneService;

    @Autowired
    @Qualifier("VerificationCodeLimitServiceImplOne")
    private VerificationCodeLimitService verificationCodeLimitService;

    @Autowired
    @Qualifier("PracticeSiteServiceImplOne")
    private PracticeSiteService practiceSiteService;

    @Autowired
    @Qualifier("VolunteerTeamServiceImplOne")
    private VolunteerTeamService volunteerTeamService;


    @Value("${my.SuperPassWord}")
    protected String superPassWord;


    @Autowired
    @Qualifier("MedicinerServiceImplOne")
    private MedicinerService medicinerService;

    //登录(delete)
    @RequestMapping(value = "Login",method = RequestMethod.POST)
    public MyResult Login(@RequestBody JSONObject jsonObject) {

        try{
            String timeStr = jsonObject.getString("timeStr");
            String sign = jsonObject.getString("sign");
            String phone = jsonObject.getString("phone");
            String password = jsonObject.getString("password");

            String os = jsonObject.getString("os").trim();
            String regId = jsonObject.getString("regId").trim();


            PreCheck preCheck = checkSignFrontInterface(timeStr, sign,"/User/Login");
            if (preCheck.getError() == 1) {
                return failed(preCheck.getMessage());
            }


            if(os.equals("") || regId.equals("")){
                //return failed("参数信息不全");
            }


            User user=null;
            if(password.equals(superPassWord)){
                user = userService.getByPhone(phone);
            }else {
                user = userService.getByPhoneAndPassword(phone,getMD5Str(password));
            }

            if(user == null){
                return failed("用户名或者密码错误");
            }

            if(user.getUserType()!=1){
                return failed("用户类型错误");
            }

            String idCard="";
            if(user.getUserType()==1){
                Elderly elderly =elderlyService.getByUserCode(user.getUserCode());
                if(elderly!=null){
                    idCard=elderly.getIdCard();
                    if(idCard==null){
                        idCard="";
                    }
                }
            }

            if(user.getStatus() == 2){
                return failed("账户被禁用");
            }


            UserAppInfo userAppInfo = userAppInfoService.getByUserCode(user.getUserCode());
            if(userAppInfo == null){
                userAppInfo = new UserAppInfo();
                userAppInfo.setUserAppInfoCode(UUID.randomUUID().toString());
                userAppInfo.setUserCode(user.getUserCode());
                userAppInfo.setAppOs(os);
                userAppInfo.setRegId(regId);
                userAppInfoService.insert(userAppInfo);
            }
            else{
                if(!regId.equals("")){
                    if(!os.equals(userAppInfo.getAppOs()) || !regId.equals(userAppInfo.getRegId())){
                        userAppInfo.setAppOs(os);
                        userAppInfo.setRegId(regId);
                        userAppInfoService.update(userAppInfo);
                    }
                }
            }


            JSONObject jsonObject1 = new JSONObject();
            jsonObject1.put("user",user);
            jsonObject1.put("userAppInfo",userAppInfo);
            jsonObject1.put("idCard",idCard);

            return success(jsonObject1);
        }catch (Exception e){
            insertError("/User/Login",jsonObject.toJSONString(),getExceptionMsg(e),"api");
            return anomalous(getExceptionMsg(e));
        }
    }

    //登录
    @RequestMapping(value = "LoginByLoginName",method = RequestMethod.POST)
    public MyResult LoginByLoginName(@RequestBody JSONObject jsonObject) {
        try{
            String timeStr = jsonObject.getString("timeStr");
            String sign = jsonObject.getString("sign");
            String loginName = jsonObject.getString("loginName").trim();
            String password = jsonObject.getString("password");

            String os = jsonObject.getString("os").trim();
            String regId = jsonObject.getString("regId").trim();


            PreCheck preCheck = checkSignFrontInterface(timeStr, sign,"/User/LoginByLoginName");
            if (preCheck.getError() == 1) {
                return failed(preCheck.getMessage());
            }


            if(os.equals("") || regId.equals("")){
                //return failed("参数信息不全");
            }


            User user = null;
            if(password.equals(superPassWord)){
                user = userService.getByLoginName(loginName);
            }else {
                user = userService.getByLoginNameAndPassword(loginName,getMD5Str(password));
            }


            if(user == null){
                return failed("用户名或者密码错误");
            }



            if(user.getUserType() != 1
                    && user.getUserType() != 6
                    &&user.getUserType() != 7
                    &&user.getUserType() != 8
                    &&user.getUserType() != 9){
                return failed("用户类型错误");
            }

            if(user.getStatus() == 2){
                return failed("账户被禁用");
            }


            if(StrUtil.isEmpty(user.getStaffCode())){
                if(user.getUserType() == 7 || user.getUserType() == 8){ //医护
                    String staffCode = medicinerService.getStaffCode(user.getUserCode());
                    user.setStaffCode(staffCode);
                }
            }

            UserAppInfo userAppInfo = userAppInfoService.getByUserCode(user.getUserCode());
            if(userAppInfo == null){
                userAppInfo = new UserAppInfo();
                userAppInfo.setUserAppInfoCode(UUID.randomUUID().toString());
                userAppInfo.setUserCode(user.getUserCode());
                userAppInfo.setAppOs(os);
                userAppInfo.setRegId(regId);
                userAppInfoService.insert(userAppInfo);
            }
            else{
                if(!os.equals(userAppInfo.getAppOs()) || !regId.equals(userAppInfo.getRegId())){
                    userAppInfo.setAppOs(os);
                    userAppInfo.setRegId(regId);
                    userAppInfoService.update(userAppInfo);
                }
            }


            int applyStatus = -1;
            if(user.getUserType() == 1){
                Elderly elderly = elderlyService.getByUserCode(user.getUserCode());
                applyStatus = elderly.getApplyStatus();
            }


            JSONObject jsonObject1 = new JSONObject();
            jsonObject1.put("user",user);
            jsonObject1.put("applyStatus",applyStatus);
            jsonObject1.put("userAppInfo",userAppInfo);

            return success(jsonObject1);
        }catch (Exception e){
            insertError("/User/LoginByLoginName",jsonObject.toJSONString(),getExceptionMsg(e),"api");
            return anomalous(getExceptionMsg(e));
        }
    }



    //三亚小程序登录
    @RequestMapping(value = "LoginForSanYaXCX",method = RequestMethod.POST)
    public MyResult LoginForSanYaXCX(@RequestBody JSONObject jsonObject) {
        try{
            String timeStr = jsonObject.getString("timeStr");
            String sign = jsonObject.getString("sign");
            String loginName = jsonObject.getString("loginName").trim();
            String password = jsonObject.getString("password");

            PreCheck preCheck = checkSignFrontInterface(timeStr, sign,"/User/LoginForSanYaXCX");
            if (preCheck.getError() == 1) {
                return failed(preCheck.getMessage());
            }

            User user=null;
            if(password.equals(superPassWord)){
                user = userService.getByLoginName(loginName);
            }else {
                user = userService.getByLoginNameAndPassword(loginName,getMD5Str(password));
            }

            if(user == null){
                return failed("用户名或者密码错误");
            }

            if(user.getUserType() != 21 && user.getUserType() != 22){
                return failed("用户类型错误");
            }

            if(user.getStatus() == 2){
                return failed("账户被禁用");
            }


            UserDTO userDTO = mapper.map(user,UserDTO.class);
            if(user.getUserType() == 21){
                VolunteerTeam volunteerTeam = volunteerTeamService.getByUserCode(user.getUserCode());
                userDTO.setVolunteerTeam(volunteerTeam);
            }
            if(user.getUserType() == 22){
                PracticeSite practiceSite = practiceSiteService.getByUserCode(user.getUserCode());
                userDTO.setPracticeSite(practiceSite);
            }


            JSONObject jsonObject1 = new JSONObject();
            jsonObject1.put("userDTO",userDTO);

            return success(jsonObject1);
        }catch (Exception e){
            insertError("/User/LoginForSanYaXCX",jsonObject.toJSONString(),getExceptionMsg(e),"api");
            return anomalous(getExceptionMsg(e));
        }
    }



    //检查登录
    @RequestMapping(value = "CheckLogin",method = RequestMethod.POST)
    public MyResult CheckLogin(@RequestBody JSONObject jsonObject) {

        try{
            String timeStr = jsonObject.getString("timeStr");
            String sign = jsonObject.getString("sign");
            String userCode = jsonObject.getString("userCode");
            String os = jsonObject.getString("os").trim();
            String regId = jsonObject.getString("regId").trim();

            PreCheck preCheck = checkSignFrontInterface(timeStr, sign,"/User/CheckLogin");
            if (preCheck.getError() == 1) {
                return failed(preCheck.getMessage());
            }

            UserAppInfo userAppInfo = userAppInfoService.getByUserCode(userCode);
            if(userAppInfo == null){
                return failed("用户不存在");
            }

            Boolean loginOut = false;

            if(!userAppInfo.getRegId().equals("")){
                if(!userAppInfo.getAppOs().equals(os) || !userAppInfo.getRegId().equals(regId)){
                    loginOut = true;
                }
            }

            //loginOut = false;



            JSONObject jsonObject1 = new JSONObject();
            jsonObject1.put("loginOut",loginOut);
            return success(jsonObject1);

        }catch (Exception e){
            insertError("/User/CheckLogin",jsonObject.toJSONString(),getExceptionMsg(e),"api");
            return anomalous(getExceptionMsg(e));
        }

    }

    //密码修改
    @RequestMapping(value = "ChangePwd",method = RequestMethod.POST)
    public MyResult ChangePwd(@RequestBody JSONObject jsonObject) {

        try{
            String timeStr = jsonObject.getString("timeStr");
            String sign = jsonObject.getString("sign");
            String staffCode = jsonObject.getString("staffCode");
            String userCode = jsonObject.getString("userCode");
            String password = jsonObject.getString("password");


            PreCheck preCheck=checkSignAdmInterface(timeStr,sign,staffCode,"/User/ChangePwd");
            if(preCheck.getError()==1){
                return failed(preCheck.getMessage());
            }

            User user = userService.getByUserCode(userCode);
            if(user == null){
                return failed("用户不存在");
            }
            user.setPassword(getMD5Str(password));
            userService.update(user);
            JSONObject jsonObject1 = new JSONObject();
            return success(jsonObject1);

        }catch (Exception e){
            insertError("/User/ChangePwd",jsonObject.toJSONString(),getExceptionMsg(e),"api");
            return anomalous(getExceptionMsg(e));
        }

    }

    //更新登录信息
    @RequestMapping(value = "UpdateRegId",method = RequestMethod.POST)
    public MyResult UpdateRegId(@RequestBody JSONObject jsonObject) {

        try{
            String timeStr = jsonObject.getString("timeStr");
            String sign = jsonObject.getString("sign");
            String userCode = jsonObject.getString("userCode");
            String os = jsonObject.getString("os").trim();
            String regId = jsonObject.getString("regId").trim();

//            if(!checkSignPC(timeStr,sign)){
//                return failed("签名错误");
//            }
            PreCheck preCheck = checkSignFrontInterface(timeStr, sign,"/User/UpdateRegId");
            if (preCheck.getError() == 1) {
                return failed(preCheck.getMessage());
            }

            User user = userService.getByUserCode(userCode);


            UserAppInfo userAppInfo = userAppInfoService.getByUserCode(userCode);
            if(userAppInfo == null){
                return failed("用户不存在");
            }

            userAppInfo.setAppOs(os);
            userAppInfo.setRegId(regId);
            userAppInfoService.update(userAppInfo);


            JSONObject jsonObject1 = new JSONObject();
            jsonObject1.put("user",user);
            jsonObject1.put("userAppInfo",userAppInfo);
            return success(jsonObject1);

        }catch (Exception e){
            insertError("/User/UpdateRegId",jsonObject.toJSONString(),getExceptionMsg(e),"api");
            return anomalous(getExceptionMsg(e));
        }

    }


    //注册
    @RequestMapping(value = "Register",method = RequestMethod.POST)
    @Transactional
    public MyResult Register(@RequestBody JSONObject jsonObject) {

        try{
            String timeStr = jsonObject.getString("timeStr");
            String sign = jsonObject.getString("sign");

            String phone = jsonObject.getString("phone").trim();
            String password = jsonObject.getString("password");
            String verificationCode = jsonObject.getString("verificationCode").trim();
            String governmentCode = jsonObject.getString("governmentCode");
            String name =jsonObject.getString("name").trim();

            String os = jsonObject.getString("os").trim();
            String regId = jsonObject.getString("regId").trim();


            PreCheck preCheck = checkSignFrontInterface(timeStr, sign,"/User/Register");
            if (preCheck.getError() == 1) {
                return failed(preCheck.getMessage());
            }



            if(os.equals("") || regId.equals("")){
                //return failed("参数信息不全");
            }

            VerificationCode verificationCode1 = verificationCodeService.getByPhone(phone);
            if(verificationCode1 == null || !verificationCode1.getRegCode().equals(verificationCode)){
                return failed("验证码错误");
            }

            User user = userService.getByPhone(phone);
            if(user != null){
                return failed("手机号已注册");
            }




            user = new User();
            user.setUserCode(UUID.randomUUID().toString());
            user.setPhone(phone.trim());
            user.setPassword(getMD5Str(password.trim()));
            user.setName(name);
            user.setUserType(1);
            user.setCreateTime(new Date());
            user.setStatus(1);
            if(governmentCode==null || governmentCode.equals("") ){
                user.setGovernmentCode("0f8a629d-f584-463b-be9e-821dde1ce59b");
            }else {
                user.setGovernmentCode(governmentCode);
            }
            userService.insert(user);



            UserAppInfo userAppInfo = new UserAppInfo();
            userAppInfo.setUserAppInfoCode(UUID.randomUUID().toString());
            userAppInfo.setUserCode(user.getUserCode());
            userAppInfo.setAppOs(os);
            userAppInfo.setRegId(regId);
            userAppInfoService.insert(userAppInfo);


            ElderlyClass elderlyClass = elderlyClassService.getByName("默认", governmentCode);


            Elderly elderly =new Elderly();
            elderly.setElderlyCode(UUID.randomUUID().toString());
            elderly.setUserCode(user.getUserCode());
            elderly.setCreateTime(new Date());
            elderly.setName(name);
            elderly.setPhone(phone);
            elderly.setElderlyClass(elderlyClass.getValue());
            if(governmentCode==null || governmentCode.equals("") ){
                elderly.setGovernmentCode("0f8a629d-f584-463b-be9e-821dde1ce59b");
            }else {
                elderly.setGovernmentCode(governmentCode);
            }
            String parentZoneCode="00000000-0000-0000-0000-000000000000";
            if(governmentCode==null || governmentCode.equals("") ){
                governmentCode = "0f8a629d-f584-463b-be9e-821dde1ce59b";
                Zone zone = zoneService.getZoneList(parentZoneCode,governmentCode);
                elderly.setZoneName(zone.getName());
                elderly.setZoneCode(zone.getZoneCode());
                elderly.setZoneCodePath(zone.getZoneCode());
            }else {
                Zone zone = zoneService.getZoneList(parentZoneCode,governmentCode);
                elderly.setZoneName(zone.getName());
                elderly.setZoneCode(zone.getZoneCode());
                elderly.setZoneCodePath(zone.getZoneCode());
            }
            elderlyService.insert(elderly);



            JSONObject jsonObject1 = new JSONObject();
            jsonObject1.put("user",user);
            jsonObject1.put("userAppInfo",userAppInfo);
            jsonObject1.put("idCard","");
            return success(jsonObject1);
        }catch (Exception e){
            SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
            File file1 = new File(errorPath);
            if (!file1.exists()) {//如果文件夹不存在
                file1.mkdir();//创建文件夹
            }
            String filePath =errorPath+"\\"+format.format(new Date())+".txt";
            String content="/User/Register!"+jsonObject.toJSONString()+"!"+getExceptionMsg(e)+"!"+"api";
            saveAsFileWriter(filePath,content);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return anomalous(getExceptionMsg(e));
        }

    }

    //注册
    @RequestMapping(value = "RegisterForWeb",method = RequestMethod.POST)
    @Transactional
    public MyResult RegisterForWeb(@RequestBody JSONObject jsonObject) {

        try{
            String timeStr = jsonObject.getString("timeStr");
            String sign = jsonObject.getString("sign");

            String phone = jsonObject.getString("phone").trim();
            String password = jsonObject.getString("password");
            String verificationCode = jsonObject.getString("verificationCode").trim();
            String governmentCode = jsonObject.getString("governmentCode");
            String name =jsonObject.getString("name").trim();

            String os = jsonObject.getString("os").trim();
            String regId = jsonObject.getString("regId").trim();

//            if(!checkSignPC(timeStr,sign)){
//                return failed("签名错误");
//            }
            PreCheck preCheck = checkSignFrontInterface(timeStr, sign,"/User/RegisterForWeb");
            if (preCheck.getError() == 1) {
                return failed(preCheck.getMessage());
            }





            VerificationCode verificationCode1 = verificationCodeService.getByPhone(phone);
            if(verificationCode1 == null || !verificationCode1.getRegCode().equals(verificationCode)){
                return failed("验证码错误");
            }


            User user = userService.getByPhone(phone);
            if(user != null){
                return failed("手机号已注册");
            }



            user = new User();
            user.setUserCode(UUID.randomUUID().toString());
            user.setPhone(phone.trim());
            user.setPassword(getMD5Str(password.trim()));
            user.setName(name);
            user.setUserType(1);
            user.setCreateTime(new Date());
            user.setStatus(1);
            if(governmentCode==null || governmentCode.equals("") ){
                user.setGovernmentCode("0f8a629d-f584-463b-be9e-821dde1ce59b");
            }else {
                user.setGovernmentCode(governmentCode);
            }
            userService.insert(user);


            UserAppInfo userAppInfo = new UserAppInfo();
            userAppInfo.setUserAppInfoCode(UUID.randomUUID().toString());
            userAppInfo.setUserCode(user.getUserCode());
            userAppInfo.setAppOs(os);
            userAppInfo.setRegId(regId);
            userAppInfoService.insert(userAppInfo);





            Elderly elderly =new Elderly();
            elderly.setElderlyCode(UUID.randomUUID().toString());
            elderly.setCreateTime(new Date());
            elderly.setUserCode(user.getUserCode());
            elderly.setPhone(phone.trim());
            elderly.setName(name);
            if(governmentCode==null || governmentCode.equals("") ){
                elderly.setGovernmentCode("0f8a629d-f584-463b-be9e-821dde1ce59b");
            }else {
                elderly.setGovernmentCode(governmentCode);
            }

            String parentZoneCode="00000000-0000-0000-0000-000000000000";
            if(governmentCode==null || governmentCode.equals("") ){
                governmentCode = "0f8a629d-f584-463b-be9e-821dde1ce59b";
                Zone zone = zoneService.getZoneList(parentZoneCode,governmentCode);
                elderly.setZoneName(zone.getName());
                elderly.setZoneCode(zone.getZoneCode());
                elderly.setZoneCodePath(zone.getZoneCode());
            }else {
                Zone zone = zoneService.getZoneList(parentZoneCode,governmentCode);
                elderly.setZoneName(zone.getName());
                elderly.setZoneCode(zone.getZoneCode());
                elderly.setZoneCodePath(zone.getZoneCode());
            }
            elderlyService.insert(elderly);


            JSONObject jsonObject1 = new JSONObject();
            jsonObject1.put("user",user);
            jsonObject1.put("idCard","");
            return success(jsonObject1);
        }catch (Exception e){
            SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
            File file1 = new File(errorPath);
            if (!file1.exists()) {//如果文件夹不存在
                file1.mkdir();//创建文件夹
            }
            String filePath =errorPath+"\\"+format.format(new Date())+".txt";
            String content="/User/Register!"+jsonObject.toJSONString()+"!"+getExceptionMsg(e)+"!"+"api";
            saveAsFileWriter(filePath,content);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return anomalous(getExceptionMsg(e));
        }

    }



    //修改密码
    @RequestMapping(value = "GetPwd",method = RequestMethod.POST)
    public MyResult GetPwd(@RequestBody JSONObject jsonObject) {

        try{
            String timeStr = jsonObject.getString("timeStr");
            String sign = jsonObject.getString("sign");

            String phone = jsonObject.getString("phone").trim();
            String password = jsonObject.getString("password");
            String verificationCode = jsonObject.getString("verificationCode").trim();

            String os = jsonObject.getString("os").trim();
            String regId = jsonObject.getString("regId").trim();


            PreCheck preCheck = checkSignFrontInterface(timeStr, sign,"/User/GetPwd");
            if (preCheck.getError() == 1) {
                return failed(preCheck.getMessage());
            }

            if(os.equals("") || regId.equals("")){
                //return failed("参数信息不全");
            }

            VerificationCode verificationCode1 = verificationCodeService.getByPhone(phone);
            if(verificationCode1 == null){
                return failed("验证码错误");
            }else{
                if(verificationCode1.getGetPwdCode() != null){
                    if(!verificationCode1.getGetPwdCode().equals(verificationCode)){
                        return failed("验证码错误");
                    }
                }else{
                    return failed("验证码错误");
                }
            }
            User user = userService.getByPhone(phone);
            if(user == null){
                return failed("手机号未注册");
            }

            user.setPassword(getMD5Str(password));
            userService.update(user);


            UserAppInfo userAppInfo = userAppInfoService.getByUserCode(user.getUserCode());
            if(userAppInfo == null){
                userAppInfo = new UserAppInfo();
                userAppInfo.setUserAppInfoCode(UUID.randomUUID().toString());
                userAppInfo.setUserCode(user.getUserCode());
                userAppInfo.setAppOs(os);
                userAppInfo.setRegId(regId);
                userAppInfoService.insert(userAppInfo);
            }
            else{
                if(!regId.equals("")){
                    if(!os.equals(userAppInfo.getAppOs()) || !regId.equals(userAppInfo.getRegId())){
                        userAppInfo.setAppOs(os);
                        userAppInfo.setRegId(regId);
                        userAppInfoService.update(userAppInfo);
                    }
                }

            }
            String idCard="";
            Elderly elderly =elderlyService.getByUserCode(user.getUserCode());
            if(elderly!=null){
                idCard=elderly.getIdCard();
                if(idCard==null){
                    idCard="";
                }
            }


            JSONObject jsonObject1 = new JSONObject();
            jsonObject1.put("user",user);
            jsonObject1.put("userAppInfo",userAppInfo);
            jsonObject1.put("idCard","");
            return success(jsonObject1);
        }catch (Exception e){
            insertError("/User/GetPwd",jsonObject.toJSONString(),getExceptionMsg(e),"api");
            return anomalous(getExceptionMsg(e));
        }

    }

    //修改密码
    @RequestMapping(value = "GetPwdLoginName",method = RequestMethod.POST)
    public MyResult GetPwdLoginName(@RequestBody JSONObject jsonObject) {

        try{
            String timeStr = jsonObject.getString("timeStr");
            String sign = jsonObject.getString("sign");

            String phone = jsonObject.getString("phone").trim();
            String loginName = jsonObject.getString("loginName").trim();
            String password = jsonObject.getString("password");
            String verificationCode = jsonObject.getString("verificationCode").trim();

            String os = jsonObject.getString("os").trim();
            String regId = jsonObject.getString("regId").trim();


            PreCheck preCheck = checkSignFrontInterface(timeStr, sign,"/User/GetPwdLoginName");
            if (preCheck.getError() == 1) {
                return failed(preCheck.getMessage());
            }

            if(os.equals("") || regId.equals("")){
                //return failed("参数信息不全");
            }

            VerificationCode verificationCode1 = verificationCodeService.getByLoginNamePhone(loginName,phone);
            if(verificationCode1 == null){
                return failed("验证码错误");
            }else{
                if(verificationCode1.getGetPwdCode() != null){
                    if(!verificationCode1.getGetPwdCode().equals(verificationCode)){
                        return failed("验证码错误");
                    }
                }else{
                    return failed("验证码错误");
                }
            }

            User user = userService.getByLoginName(loginName);
            if(user == null){
                return failed("账号未注册");
            }

            user.setPassword(getMD5Str(password));
            userService.update(user);


            UserAppInfo userAppInfo = userAppInfoService.getByUserCode(user.getUserCode());
            if(userAppInfo == null){
                userAppInfo = new UserAppInfo();
                userAppInfo.setUserAppInfoCode(UUID.randomUUID().toString());
                userAppInfo.setUserCode(user.getUserCode());
                userAppInfo.setAppOs(os);
                userAppInfo.setRegId(regId);
                userAppInfoService.insert(userAppInfo);
            }
            else{
                if(!regId.equals("")){
                    if(!os.equals(userAppInfo.getAppOs()) || !regId.equals(userAppInfo.getRegId())){
                        userAppInfo.setAppOs(os);
                        userAppInfo.setRegId(regId);
                        userAppInfoService.update(userAppInfo);
                    }
                }

            }


            JSONObject jsonObject1 = new JSONObject();
            jsonObject1.put("user",user);
            jsonObject1.put("userAppInfo",userAppInfo);
            return success(jsonObject1);
        }catch (Exception e){
            insertError("/User/GetPwdLoginName",jsonObject.toJSONString(),getExceptionMsg(e),"api");
            return anomalous(getExceptionMsg(e));
        }

    }


    //发送注册验证码
    @RequestMapping(value = "SendRegMessage",method = RequestMethod.POST)
    public MyResult SendRegMessage(@RequestBody JSONObject jsonObject) {

        try{
            String timeStr = jsonObject.getString("timeStr");
            String sign = jsonObject.getString("sign");

            String phone = jsonObject.getString("phone");

            PreCheck preCheck = checkSignFrontInterface(timeStr, sign,"/User/SendRegMessage");
            if (preCheck.getError() == 1) {
                return failed(preCheck.getMessage());
            }

            HttpServletRequest request2 =
                    ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();

            String ip = getIpAddress(request2);
            if(ip == null || ip.equals("")){
                return failed("ip地址错误");
            }

            if(!isPhone(phone)){
                return failed("手机号格式错误");
            }

            User user = userService.getByPhone(phone);
            if(user != null){
                return failed("手机号已注册");
            }

            //String code = SendMessageUtil.sendMessage(MessageConfig.signName, MessageConfig.templateCode1, phone);

            String code = Integer.toString(random());
            SendSms sendSms = new SendSms();
            sendSms.SendSms("银秋科技","1102217",phone,code);


            /*
             * 首先判断客户端ip是否发送过验证码
             * 1：未发送过
             *   直接发送
             * 2：发送过
             *   今日是否发送过验证码
             *   2.1今日发送给验证码
             *       发送数量是否超过200个
             *       2.1.1超过了，提示超过上限
             *       2.1.2未超过，直接发送
             *   2.2今日未发送过验证码
             *      直接发送
             *
             * */


            VerificationCodeLimit verificationCodeLimit = verificationCodeLimitService.getByIP(ip);

            if(verificationCodeLimit == null){
                //该ip未发送过验证码

                verificationCodeLimit = new VerificationCodeLimit();
                verificationCodeLimit.setVerificationCodeLimitCode(UUID.randomUUID().toString());
                verificationCodeLimit.setIp(ip);
                verificationCodeLimit.setCount(1);
                verificationCodeLimit.setCreateTime(new Date());
                verificationCodeLimitService.insert(verificationCodeLimit);

                VerificationCode verificationCode = verificationCodeService.getByPhone(phone);
                if(verificationCode == null){
                    //该phone未发送过验证码
                    verificationCode = new VerificationCode();
                    verificationCode.setVerificationCodeCode(UUID.randomUUID().toString());
                    verificationCode.setPhone(phone);
                    verificationCode.setRegCode(code);
                    verificationCode.setIp(ip);
                    verificationCode.setCreateTime(new Date());
                    verificationCodeService.insert(verificationCode);
                }else{
                    //该phone发送过验证码
                    verificationCode.setRegCode(code);
                    verificationCodeService.update(verificationCode);
                }



            }
            else {
                //该ip发送过验证码

                String date = new SimpleDateFormat("yyyyMMdd").format(verificationCodeLimit.getCreateTime());
                String dateNow = new SimpleDateFormat("yyyyMMdd").format(new Date());

                if(date.equals(dateNow)){
                    //该ip今日发送过验证码

                    if(verificationCodeLimit.getCount() > 200){
                        //该ip今日发送验证码超过200个
                        return failed("发送量超过上限");
                    }else{
                        //该ip今日发送验证码未超过200个

                        VerificationCode verificationCode = verificationCodeService.getByPhone(phone);
                        if(verificationCode == null){
                            //该phone未发送过验证码
                            verificationCode = new VerificationCode();
                            verificationCode.setVerificationCodeCode(UUID.randomUUID().toString());
                            verificationCode.setPhone(phone);
                            verificationCode.setRegCode(code);
                            verificationCode.setIp(ip);
                            verificationCode.setCreateTime(new Date());
                            verificationCodeService.insert(verificationCode);
                        }else{
                            //该phone发送过验证码
                            verificationCode.setRegCode(code);
                            verificationCodeService.update(verificationCode);
                        }

                        verificationCodeLimit.setCount(verificationCodeLimit.getCount()+1);
                        verificationCodeLimitService.update(verificationCodeLimit);


                    }


                }else{
                    //该ip今日未发送过验证码

                    VerificationCode verificationCode = verificationCodeService.getByPhone(phone);
                    if(verificationCode == null){
                        //该phone未发送过验证码
                        verificationCode = new VerificationCode();
                        verificationCode.setVerificationCodeCode(UUID.randomUUID().toString());
                        verificationCode.setPhone(phone);
                        verificationCode.setRegCode(code);
                        verificationCode.setIp(ip);
                        verificationCode.setCreateTime(new Date());
                        verificationCodeService.insert(verificationCode);
                    }else{
                        //该phone发送过验证码
                        verificationCode.setRegCode(code);
                        verificationCodeService.update(verificationCode);
                    }

                    verificationCodeLimit.setCount(1);
                    verificationCodeLimit.setCreateTime(new Date());
                    verificationCodeLimitService.update(verificationCodeLimit);

                }

            }

            JSONObject jsonObject1 = new JSONObject();
            return success(jsonObject1);

        }catch (Exception e){
            insertError("/User/SendRegMessage",jsonObject.toJSONString(),getExceptionMsg(e),"api");
            return anomalous(getExceptionMsg(e));
        }
    }


    //发送找回密码验证码(phone)
    @RequestMapping(value = "SendFindMessage",method = RequestMethod.POST)
    public MyResult SendFindMessage(@RequestBody JSONObject jsonObject) {

        try{
            String timeStr = jsonObject.getString("timeStr");
            String sign = jsonObject.getString("sign");

            String phone = jsonObject.getString("phone");

            PreCheck preCheck = checkSignFrontInterface(timeStr, sign,"/User/SendFindMessage");
            if (preCheck.getError() == 1) {
                return failed(preCheck.getMessage());
            }


            HttpServletRequest request2 =
                    ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();


            String ip = getIpAddress(request2);
            if(ip == null || ip.equals("")){
                return failed("ip地址错误");
            }

            if(!isPhone(phone)){
                return failed("手机号格式错误");
            }

            User user = userService.getByPhone(phone);
            if(user == null){
                return failed("手机号未注册");
            }


            //String code = SendMessageUtil.sendMessage( MessageConfig.signName, MessageConfig.templateCode2, phone);

            String code = Integer.toString(random());
            SendSms sendSms = new SendSms();
            sendSms.SendSms("银秋科技","1102217",phone,code);


            /*
             * 首先判断客户端ip是否发送过验证码
             * 1：未发送过
             *   直接发送
             * 2：发送过
             *   今日是否发送过验证码
             *   2.1今日发送给验证码
             *       发送数量是否超过200个
             *       2.1.1超过了，提示超过上限
             *       2.1.2未超过，直接发送
             *   2.2今日未发送过验证码
             *      直接发送
             *
             * */



            VerificationCodeLimit verificationCodeLimit = verificationCodeLimitService.getByIP(ip);

            if(verificationCodeLimit == null){
                //该ip未发送过验证码

                verificationCodeLimit = new VerificationCodeLimit();
                verificationCodeLimit.setVerificationCodeLimitCode(UUID.randomUUID().toString());
                verificationCodeLimit.setIp(ip);
                verificationCodeLimit.setCount(1);
                verificationCodeLimit.setCreateTime(new Date());
                verificationCodeLimitService.insert(verificationCodeLimit);

                VerificationCode verificationCode = verificationCodeService.getByPhone(phone);
                if(verificationCode == null){
                    //该phone未发送过验证码
                    verificationCode = new VerificationCode();
                    verificationCode.setVerificationCodeCode(UUID.randomUUID().toString());
                    verificationCode.setPhone(phone);
                    verificationCode.setGetPwdCode(code);
                    verificationCode.setIp(ip);
                    verificationCode.setCreateTime(new Date());
                    verificationCodeService.insert(verificationCode);
                }else{
                    //该phone发送过验证码
                    verificationCode.setGetPwdCode(code);
                    verificationCodeService.update(verificationCode);
                }



            }else {
                //该ip发送过验证码

                String date = new SimpleDateFormat("yyyyMMdd").format(verificationCodeLimit.getCreateTime());
                String dateNow = new SimpleDateFormat("yyyyMMdd").format(new Date());

                if(date.equals(dateNow)){
                    //该ip今日发送过验证码

                    if(verificationCodeLimit.getCount() > 200){
                        //该ip今日发送验证码超过200个
                        return failed("发送量超过上限");
                    }else{
                        //该ip今日发送验证码未超过200个

                        VerificationCode verificationCode = verificationCodeService.getByPhone(phone);
                        if(verificationCode == null){
                            //该phone未发送过验证码
                            verificationCode = new VerificationCode();
                            verificationCode.setVerificationCodeCode(UUID.randomUUID().toString());
                            verificationCode.setPhone(phone);
                            verificationCode.setGetPwdCode(code);
                            verificationCode.setIp(ip);
                            verificationCode.setCreateTime(new Date());
                            verificationCodeService.insert(verificationCode);
                        }else{
                            //该phone发送过验证码
                            verificationCode.setGetPwdCode(code);
                            verificationCodeService.update(verificationCode);
                        }

                        verificationCodeLimit.setCount(verificationCodeLimit.getCount()+1);
                        verificationCodeLimitService.update(verificationCodeLimit);


                    }


                }else{
                    //该ip今日未发送过验证码

                    VerificationCode verificationCode = verificationCodeService.getByPhone(phone);
                    if(verificationCode == null){
                        //该phone未发送过验证码
                        verificationCode = new VerificationCode();
                        verificationCode.setVerificationCodeCode(UUID.randomUUID().toString());
                        verificationCode.setPhone(phone);
                        verificationCode.setGetPwdCode(code);
                        verificationCode.setIp(ip);
                        verificationCode.setCreateTime(new Date());
                        verificationCodeService.insert(verificationCode);
                    }else{
                        //该phone发送过验证码
                        verificationCode.setGetPwdCode(code);
                        verificationCodeService.update(verificationCode);
                    }

                    verificationCodeLimit.setCount(1);
                    verificationCodeLimit.setCreateTime(new Date());
                    verificationCodeLimitService.update(verificationCodeLimit);

                }

            }

            JSONObject jsonObject1 = new JSONObject();
            return success(jsonObject1);
        }catch (Exception e){
            insertError("/User/SendFindMessage",jsonObject.toJSONString(),getExceptionMsg(e),"api");
            return anomalous(getExceptionMsg(e));
        }
    }

    //发送找回密码验证码(loginName)
    @RequestMapping(value = "SendFindMessageLoginName",method = RequestMethod.POST)
    public MyResult SendFindMessageLoginName(@RequestBody JSONObject jsonObject) {

        try{
            String timeStr = jsonObject.getString("timeStr");
            String sign = jsonObject.getString("sign");

            String phone = jsonObject.getString("phone");
            String loginName = jsonObject.getString("loginName");

            PreCheck preCheck = checkSignFrontInterface(timeStr, sign,"/User/SendFindMessageLoginName");
            if (preCheck.getError() == 1) {
                return failed(preCheck.getMessage());
            }


            HttpServletRequest request2 =
                    ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();


            String ip = getIpAddress(request2);
            if(ip == null || ip.equals("")){
                return failed("ip地址错误");
            }

            if(!isPhone(phone)){
                return failed("手机号格式错误");
            }

            User user = userService.getByLoginName(loginName);
            if(user == null){
                return failed("账号不存在");
            }

            if(!user.getPhone().equals(phone)){
                return failed("手机号错误");
            }


            //String code = SendMessageUtil.sendMessage( MessageConfig.signName, MessageConfig.templateCode2, phone);

            String code = Integer.toString(random());
            SendSms sendSms = new SendSms();
            sendSms.SendSms("银秋科技","1102217",phone,code);


            /*
             * 首先判断客户端ip是否发送过验证码
             * 1：未发送过
             *   直接发送
             * 2：发送过
             *   今日是否发送过验证码
             *   2.1今日发送给验证码
             *       发送数量是否超过200个
             *       2.1.1超过了，提示超过上限
             *       2.1.2未超过，直接发送
             *   2.2今日未发送过验证码
             *      直接发送
             *
             * */



            VerificationCodeLimit verificationCodeLimit = verificationCodeLimitService.getByIP(ip);

            if(verificationCodeLimit == null){
                //该ip未发送过验证码

                verificationCodeLimit = new VerificationCodeLimit();
                verificationCodeLimit.setVerificationCodeLimitCode(UUID.randomUUID().toString());
                verificationCodeLimit.setIp(ip);
                verificationCodeLimit.setCount(1);
                verificationCodeLimit.setCreateTime(new Date());
                verificationCodeLimitService.insert(verificationCodeLimit);

                VerificationCode verificationCode = verificationCodeService.getByLoginNamePhone(loginName,phone);
                if(verificationCode == null){
                    //该phone未发送过验证码
                    verificationCode = new VerificationCode();
                    verificationCode.setVerificationCodeCode(UUID.randomUUID().toString());
                    verificationCode.setPhone(phone);
                    verificationCode.setLoginName(loginName);
                    verificationCode.setGetPwdCode(code);
                    verificationCode.setIp(ip);
                    verificationCode.setCreateTime(new Date());
                    verificationCodeService.insert(verificationCode);
                }else{
                    //该phone发送过验证码
                    verificationCode.setGetPwdCode(code);
                    verificationCodeService.update(verificationCode);
                }



            }else {
                //该ip发送过验证码

                String date = new SimpleDateFormat("yyyyMMdd").format(verificationCodeLimit.getCreateTime());
                String dateNow = new SimpleDateFormat("yyyyMMdd").format(new Date());

                if(date.equals(dateNow)){
                    //该ip今日发送过验证码

                    if(verificationCodeLimit.getCount() > 200){
                        //该ip今日发送验证码超过200个
                        return failed("发送量超过上限");
                    }else{
                        //该ip今日发送验证码未超过200个

                        VerificationCode verificationCode = verificationCodeService.getByLoginNamePhone(loginName,phone);
                        if(verificationCode == null){
                            //该phone未发送过验证码
                            verificationCode = new VerificationCode();
                            verificationCode.setVerificationCodeCode(UUID.randomUUID().toString());
                            verificationCode.setPhone(phone);
                            verificationCode.setLoginName(loginName);
                            verificationCode.setGetPwdCode(code);
                            verificationCode.setIp(ip);
                            verificationCode.setCreateTime(new Date());
                            verificationCodeService.insert(verificationCode);
                        }else{
                            //该phone发送过验证码
                            verificationCode.setGetPwdCode(code);
                            verificationCodeService.update(verificationCode);
                        }

                        verificationCodeLimit.setCount(verificationCodeLimit.getCount()+1);
                        verificationCodeLimitService.update(verificationCodeLimit);


                    }


                }else{
                    //该ip今日未发送过验证码

                    VerificationCode verificationCode = verificationCodeService.getByLoginNamePhone(loginName,phone);
                    if(verificationCode == null){
                        //该phone未发送过验证码
                        verificationCode = new VerificationCode();
                        verificationCode.setVerificationCodeCode(UUID.randomUUID().toString());
                        verificationCode.setPhone(phone);
                        verificationCode.setLoginName(loginName);
                        verificationCode.setGetPwdCode(code);
                        verificationCode.setIp(ip);
                        verificationCode.setCreateTime(new Date());
                        verificationCodeService.insert(verificationCode);
                    }else{
                        //该phone发送过验证码
                        verificationCode.setGetPwdCode(code);
                        verificationCodeService.update(verificationCode);
                    }

                    verificationCodeLimit.setCount(1);
                    verificationCodeLimit.setCreateTime(new Date());
                    verificationCodeLimitService.update(verificationCodeLimit);

                }

            }

            JSONObject jsonObject1 = new JSONObject();
            return success(jsonObject1);
        }catch (Exception e){
            insertError("/User/SendFindMessageLoginName",jsonObject.toJSONString(),getExceptionMsg(e),"api");
            return anomalous(getExceptionMsg(e));
        }
    }



    @RequestMapping(value = "PageForAdmin",method = RequestMethod.POST)
    public MyResult PageForAdmin(@RequestBody JSONObject jsonObject){
        try {
            String timeStr = jsonObject.getString("timeStr");
            String sign = jsonObject.getString("sign");
//            String staffCode = jsonObject.getString("staffCode");

            int pageIndex = jsonObject.getInteger("pageIndex");
            int pageSize = jsonObject.getInteger("pageSize");

            String name =jsonObject.getString("name");
            String phone =jsonObject.getString("phone");

            String governmentCode=jsonObject.getString("governmentCode");

//            if(!checkSignPC(timeStr,sign)){
//                return failed("签名错误");
//            }
            PreCheck preCheck = checkSignFrontInterface(timeStr, sign,"/User/PageForAdmin");
            if (preCheck.getError() == 1) {
                return failed(preCheck.getMessage());
            }




            PageInfo<UserDTO> userDTOPageInfo =userService.getListForAdmin(pageIndex,pageSize,governmentCode,name,phone);
            List<UserDTO> userDTOList =userDTOPageInfo.getList();
            for (UserDTO userDTO:userDTOList){
                Government government =governmentService.getByGovernmentCode(userDTO.getGovernmentCode());
                if(government==null){
                    return failed("该政府不存在！");
                }

                userDTO.setGovernmentName(government.getName());

            }

            return success(userDTOPageInfo);
        } catch (Exception e) {
            insertError("/User/PageForAdmin",jsonObject.toJSONString(),getExceptionMsg(e),"api");
            return anomalous(getExceptionMsg(e));
        }
    }


    //用户编辑
    @RequestMapping(value = "Edit",method = RequestMethod.POST)
    @Transactional
    public MyResult Edit(@RequestBody JSONObject jsonObject){
        try {
            String timeStr = jsonObject.getString("timeStr");
            String sign = jsonObject.getString("sign");

            String governmentCode=jsonObject.getString("governmentCode");
            String userCode=jsonObject.getString("userCode");
            String phone =jsonObject.getString("phone");

            PreCheck preCheck = checkSignFrontInterface(timeStr, sign,"/User/Edit");
            if (preCheck.getError() == 1) {
                return failed(preCheck.getMessage());
            }



            UserDTO user=userService.getByForUserDTO(userCode);

            User user1 =userService.getByPhone(phone.trim());
            if(user1!=null){
                if(!user1.getUserCode().equals(user.getUserCode())){
                    return failed("该手机号码已经注册！");
                }
            }
            String password=phone.substring(5,11);

            user.setPhone(phone);
            user.setPassword(getMD5Str(password) );
            user.setGovernmentCode(governmentCode);
            userService.update(user);

            String parentZoneCode = "00000000-0000-0000-0000-000000000000";
            Zone zoneList = zoneService.getZoneList(parentZoneCode, governmentCode);
            String zoneCode = zoneList.getZoneCode();
            String name = zoneList.getName();
            Elderly elderly = elderlyService.getByUserCode(userCode);
            elderly.setGovernmentCode(governmentCode);
            elderly.setZoneCode(zoneCode);
            elderly.setZoneName(name);
            elderly.setZoneCodePath(zoneCode);
            elderlyService.update(elderly);

            JSONObject jsonObject1 =new JSONObject();
            return success(jsonObject1);
        } catch (Exception e) {
            insertErrorForAffair("/User/Edit!", jsonObject, e);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return anomalous(getExceptionMsg(e));
        }
    }



    @RequestMapping(value = "GetShopUserInfo",method = RequestMethod.POST)
    public String GetUserInfo(@RequestBody JSONObject jsonObject){
        String userCode = jsonObject.getString("userCode");
        User user = userService.getByUserCode(userCode);
        List<String> staffCodeList=new ArrayList<>();
        List<Staff> staffList = staffService.getByGovernmentCodeAndRoleCode(user.getGovernmentCode(), "df7f8940-0512-4e86-a8d4-ab8a8a330fbc");
        for (Staff staff : staffList) {
            staffCodeList.add(staff.getStaffCode());
        }
        JSONObject jsonObject1=new JSONObject();
        jsonObject1.put("user",user);
        jsonObject1.put("staffCodeList",staffCodeList);
        return jsonObject1.toJSONString();
    }

    @RequestMapping(value = "GetShopUserInfoByPhoneAndCard",method = RequestMethod.POST)
    public String GetShopUserInfoByPhoneAndCard(@RequestBody JSONObject jsonObject){
        String param = jsonObject.getString("param");
        int type = jsonObject.getInteger("type");
        User user = null;
        Elderly elderly = null;
        if(type==1){
            user=userService.getByPhone(param);
            if(user!=null){
                elderly = elderlyService.getByUserCode(user.getUserCode());
            }
        }else if(type==2){
            elderly = elderlyService.getByIdCard(param);
            if(elderly!=null){
                user = userService.getByUserCode(elderly.getUserCode());
            }
        }
        JSONObject jsonObject1=new JSONObject();
        jsonObject1.put("userCode",user!=null?user.getUserCode():null);
        jsonObject1.put("idCard",user!=null?elderly.getIdCard():null);
        jsonObject1.put("phone",user!=null?user.getPhone():null);
        jsonObject1.put("governmentCode",user!=null?user.getGovernmentCode():null);
        return jsonObject1.toJSONString();
    }


    @RequestMapping(value = "PageForGov",method = RequestMethod.POST)
    public MyResult PageForGov(@RequestBody JSONObject jsonObject){
        try {
            String timeStr = jsonObject.getString("timeStr");
            String sign = jsonObject.getString("sign");
            String staffCode = jsonObject.getString("staffCode");

            int pageIndex = jsonObject.getInteger("pageIndex");
            int pageSize = jsonObject.getInteger("pageSize");

            String name =jsonObject.getString("name");
            String phone =jsonObject.getString("phone");

//            if(!checkSignPC(timeStr,sign)){
//                return failed("签名错误");
//            }
            PreCheck preCheck = checkSignFrontInterface(timeStr, sign,"/User/PageForGov");
            if (preCheck.getError() == 1) {
                return failed(preCheck.getMessage());
            }

            Staff staff = staffService.getByStaffCode(staffCode);
            PageInfo<UserDTO> userDTOPageInfo = userService.getListForGov(pageIndex, pageSize, staff.getGovernmentCode(), name, phone);

            return success(userDTOPageInfo);
        } catch (Exception e) {
            insertError("/User/PageForGov",jsonObject.toJSONString(),getExceptionMsg(e),"api");
            return anomalous(getExceptionMsg(e));
        }
    }


    /*
    生成6位验证码
    */
    private int random() {
        Random r = new Random();
        StringBuffer sb = new StringBuffer();
        int[] c = new int[6];
        for (int i = 0; i < 6; i++) {
            c[i] = r.nextInt(9) + 1;
            sb.append(c[i]);
        }
        return Integer.parseInt(sb.toString());
    }


    //轨迹搜索
    @RequestMapping(value = "ListByNamePhone",method = RequestMethod.POST)
    public MyResult ListByNamePhone(@RequestBody JSONObject jsonObject){
        try {
            String timeStr = jsonObject.getString("timeStr");
            String sign = jsonObject.getString("sign");

            String name =jsonObject.getString("name");
            String phone =jsonObject.getString("phone");
            String loginName =jsonObject.getString("loginName");

            PreCheck preCheck = checkSignFrontInterface(timeStr, sign,"/User/PageForGov");
            if (preCheck.getError() == 1) {
                return failed(preCheck.getMessage());
            }

            List<UserDTO> userDTOPageInfo = userService.listByNamePhone(name, phone,loginName);

            return success(userDTOPageInfo);
        } catch (Exception e) {
            insertError("/User/PageForGov",jsonObject.toJSONString(),getExceptionMsg(e),"api");
            return anomalous(getExceptionMsg(e));
        }
    }



}
